#! /bin/bash

# --------------------------------------------------------------------------
#
# This script checks the status of plotting on the command line.
#
# yqm_leaf@163.com
#
# 04/30/21
#
# --------------------------------------------------------------------------

[ $# -lt 1 ] && { echo "Usage ${0} [log file(s)]" ; exit 1 ; }

# This number is what chia-blockchain-gui use.
MAGIC_NUM=2626

for log_file in $@ ; do
    [ -f "${log_file}" ] || \
        { echo "Log file: ${log_file} is not a file." ; continue ; }
    [ -r "${log_file}" ] || \
        { echo "Log file: ${log_file} is inaccessible." ; continue ; }
    log_lines=$(wc -l ${log_file} | awk '{ print $1 }')
    [ $log_lines -gt $MAGIC_NUM ] && \
        { echo -e "$log_file\t100%" ; continue ; }
    percentage=$(echo $(echo "scale = 3 ; ${log_lines} / ${MAGIC_NUM} * 100" | bc)%)
    echo -e "$log_file\t$percentage"
done
